const {MongoClient} = require('mongodb');
const url = 'mongodb://admin:%40zhao116524@43.129.77.109:27017';
const client = new MongoClient(url);
const fs = require('fs')
const {dataTransferToStatement} = require('./script/cmaera')

// Database Name
const dbName = 'swift-dev';

async function main() {
    console.log('=======start connect======')
    // Use connect method to connect to the server
    await client.connect();
    console.log('Connected successfully to server');
    const db = client.db(dbName);
    const collection = await db.collection('dqa_swallows');
    let camDataJson = fs.readFileSync('./script/cam-003.json');
    let camData = JSON.parse(camDataJson)
    for (let date in camData) {
        console.log('==========start deal with======',date);
        let data = dataTransferToStatement(camDataJson);
        console.log('data: ', data);
        // const list = await collection.findOne({})
    }
    // the following code examples can be pasted here...
    return 'done.';
}

main().then(console.log).catch(console.error). finally(() => client.close());
